package ch.csp;

import java.util.ArrayList;

import ch.csp.exchange.ParagraphWithLineAndWords;
import ch.csp.exchange.ParagraphWithLines;
import ch.csp.exchange.ParagraphWithWords;
import ch.csp.io.FileReaderWriter;
import ch.csp.transformer.ColumnedLineTransformer;
import ch.csp.transformer.JustifyTransformer;
import ch.csp.transformer.LineTransformer;

public class Main {

	public static void main(String[] args) {
		if(args.length != 4){
			System.out.println("Parameters:");
			System.out.println(" inputFile.txt");
			System.out.println(" outputFile.txt");
			System.out.println(" columns (number)");
			System.out.println(" width (number)");
			return;
		}
		String inputFile = args[0];
		String outputFile = args[1];
		int columns = Integer.parseInt(args[2]);
		int columnWidth = Integer.parseInt(args[3]);
		
		//Teil Claudio
		FileReaderWriter frw = new FileReaderWriter(inputFile, outputFile);
		ArrayList<ParagraphWithWords> paragraphsWithWords = frw.readFile();
		
		
		//Teil Sebastian
		LineTransformer lineTransformer = new LineTransformer(paragraphsWithWords, columnWidth);
		ArrayList<ParagraphWithLineAndWords> paragraphsWithLines = lineTransformer.transform();
		
		//Teil Curdin
		JustifyTransformer justifyTransformer = new JustifyTransformer(paragraphsWithLines);
		ArrayList<ParagraphWithLines> paragraphsWithJustifiedLines = justifyTransformer.transform();
		
		ColumnedLineTransformer columnedLines = new ColumnedLineTransformer(paragraphsWithJustifiedLines, columns);
		ArrayList<String> lines = columnedLines.transform();
		frw.writeFile(lines);
		
		System.out.println("Die Zieldatei wurde geschrieben");
	}

}
